//把packages目录下所有包都进行打包

const fs = require('fs');
const execa = require('execa');

const targets = fs.readdirSync('packages').filter(f => {
  return fs.statSync(`packages/${f}`).isDirectory();
});
//console.log(targets); //[ 'reactivity', 'shared' ]

runParallel(targets,build)
  .then(()=>{
    //打印日志撒的
  })

function runParallel(targets, iterateFn) {
  const res = [];
  for(const item of targets){
    const p = iterateFn(item);
    res.push(p);
  }

  return Promise.all(res);
}

async function build(target){
  console.log('build target:',target)
  //开启子进程用rollup进行打包
  await execa(
    'rollup',
    ['-c','--environment',`TARGET:${target}`], // rollup -c --environment TARGET:shared
    {stdio:'inherit'} //子进程打包的信息共享给父进程
  );
}
